package com.hrsoft.edi.stub;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import com.hrsoft.edi.stub.consant.AppInfo;
import com.hrsoft.edi.stub.internal.CustomerQimenClient;
import com.hrsoft.edi.stub.request.EntryorderCreateRequest;
import com.qimen.api.response.EntryorderCreateResponse;
import com.taobao.api.ApiException;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author zxf
 * @date 2019/8/6 13:33
 */
@Slf4j
public class EntryOrderCreateTestSN
{
    public static void create()
        throws ApiException
    {
        CustomerQimenClient client = new CustomerQimenClient(AppInfo.URL, AppInfo.APP_KEY, AppInfo.SECRET);
        EntryorderCreateRequest createRequest = new EntryorderCreateRequest();
        createRequest.setCustomerId(AppInfo.CUSTOMER_ID);
        createRequest.setVersion("2.0");
        EntryorderCreateRequest.EntryOrder entryOrder = new EntryorderCreateRequest.EntryOrder();
        entryOrder.setWarehouseCode(AppInfo.WAREHOUSE_CODE);
        entryOrder.setOwnerCode(AppInfo.OWNER_CODE);
        entryOrder.setLogisticsCode("YTO");
        entryOrder.setEntryOrderCode("SN" + RandomUtil.randomNumbers(15));
        entryOrder.setExpectEndTime(DateUtil.formatDateTime(new Date()));
        entryOrder.setExpectStartTime(DateUtil.formatDateTime(new Date()));
        entryOrder.setOperateTime(DateUtil.formatDateTime(new Date()));
        entryOrder.setBusinessId("dssdasdas");
        entryOrder.setPurchaseOrderCode("SN" + RandomUtil.randomNumbers(15));
        entryOrder.setOrderType("CGRK");
        EntryorderCreateRequest.SenderInfo senderInfo = new EntryorderCreateRequest.SenderInfo();
        senderInfo.setName("我是客户");
        senderInfo.setMobile("15252154523");
        senderInfo.setProvince("广东省");
        senderInfo.setCity("广州市");
        senderInfo.setDetailAddress("我是客户");
        EntryorderCreateRequest.ReceiverInfo receiverInfo = new EntryorderCreateRequest.ReceiverInfo();
        receiverInfo.setName("我是客户");
        receiverInfo.setMobile("15252154523");
        receiverInfo.setProvince("广东省");
        receiverInfo.setCity("广州市");
        receiverInfo.setDetailAddress("我是客户");
        entryOrder.setReceiverInfo(receiverInfo);
        entryOrder.setSenderInfo(senderInfo);
        createRequest.setEntryOrder(entryOrder);
        EntryorderCreateRequest.RelatedOrder relatedOrder = new EntryorderCreateRequest.RelatedOrder();
        relatedOrder.setOrderCode("111");
        relatedOrder.setOrderType("CG");
        List<EntryorderCreateRequest.RelatedOrder> list = new ArrayList<>();
        list.add(relatedOrder);
        entryOrder.setRelatedOrders(list);
        EntryorderCreateRequest.OrderLine orderLine1 = new EntryorderCreateRequest.OrderLine();
        orderLine1.setItemCode("826002");
        orderLine1.setItemName("826002");
        orderLine1.setPlanQty("5");
        orderLine1.setActualPrice("1");
        orderLine1.setInventoryType("ZP");
        orderLine1.setOwnerCode(AppInfo.OWNER_CODE);
        List<String> list1 = new ArrayList<>();
        list1.add("CSSN020026");
        list1.add("CSSN020027");
        list1.add("CSSN020028");
        list1.add("CSSN020029");
        list1.add("CSSN010030");
        EntryorderCreateRequest.OrderLine.ExtendProps extendProps1 =
            new EntryorderCreateRequest.OrderLine.ExtendProps();
        extendProps1.setSnBoxCode("BoxCSSN02001");
        orderLine1.setExtendProps(extendProps1);
        orderLine1.setSnList(list1);

        EntryorderCreateRequest.OrderLine orderLine2 = new EntryorderCreateRequest.OrderLine();
        orderLine2.setItemCode("826002");
        orderLine2.setItemName("826002");
        orderLine2.setPlanQty("5");
        orderLine2.setActualPrice("1");
        orderLine2.setInventoryType("ZP");
        orderLine2.setOwnerCode(AppInfo.OWNER_CODE);
        EntryorderCreateRequest.OrderLine.ExtendProps extendProps2 =
            new EntryorderCreateRequest.OrderLine.ExtendProps();
        extendProps2.setSnBoxCode("BoxCSSN02002");
        orderLine2.setExtendProps(extendProps2);
        List<String> list2 = new ArrayList<>();
        list2.add("CSSN010031");
        list2.add("CSSN010032");
        list2.add("CSSN010033");
        list2.add("CSSN010034");
        list2.add("CSSN010035");
        orderLine2.setSnList(list2);

        EntryorderCreateRequest.OrderLine orderLine3 = new EntryorderCreateRequest.OrderLine();
        orderLine3.setItemCode("826002");
        orderLine3.setItemName("826002");
        orderLine3.setPlanQty("5");
        orderLine3.setActualPrice("1");
        orderLine3.setInventoryType("ZP");
        orderLine3.setOwnerCode(AppInfo.OWNER_CODE);
        EntryorderCreateRequest.OrderLine.ExtendProps extendProps3 =
            new EntryorderCreateRequest.OrderLine.ExtendProps();
        extendProps3.setSnBoxCode("BoxCSSN02003");
        orderLine3.setExtendProps(extendProps3);
        List<String> list3 = new ArrayList<>();
        list3.add("CSSN010036");
        list3.add("CSSN010037");
        list3.add("CSSN010038");
        list3.add("CSSN010039");
        list3.add("CSSN010040");
        orderLine3.setSnList(list3);

//        EntryorderCreateRequest.OrderLine orderLine4=new EntryorderCreateRequest.OrderLine();
//        orderLine4.setItemCode("826002");
//        orderLine4.setItemName("826002");
//        orderLine4.setPlanQty("5");
//        orderLine4.setActualPrice("1");
//        orderLine4.setInventoryType("ZP");
//        orderLine4.setOwnerCode(AppInfo.OWNER_CODE);
//        EntryorderCreateRequest.OrderLine.ExtendProps extendProps4 = new EntryorderCreateRequest.OrderLine.ExtendProps();
//        extendProps4.setSnBoxCode("BoxCSSN01004");
//        orderLine4.setExtendProps(extendProps4);
//        EntryorderCreateRequest.SnList snList3 = new EntryorderCreateRequest.SnList();
//        List<String> list4 = new ArrayList<>();
//        list4.add("CSSN010041");
//        list4.add("CSSN010042");
//        list4.add("CSSN010043");
//        list4.add("CSSN010044");
//        list4.add("CSSN010045");
//        snList3.setSn(list4);
//        orderLine4.setSnList(snList3);
//
//        EntryorderCreateRequest.OrderLine orderLine5=new EntryorderCreateRequest.OrderLine();
//        orderLine5.setItemCode("826002");
//        orderLine5.setItemName("826002");
//        orderLine5.setPlanQty("5");
//        orderLine5.setActualPrice("1");
//        orderLine5.setInventoryType("ZP");
//        orderLine5.setOwnerCode(AppInfo.OWNER_CODE);
//        EntryorderCreateRequest.OrderLine.ExtendProps extendProps5 = new EntryorderCreateRequest.OrderLine.ExtendProps();
//        extendProps5.setSnBoxCode("BoxCSSN01005");
//        orderLine5.setExtendProps(extendProps5);
//        EntryorderCreateRequest.SnList snList4 = new EntryorderCreateRequest.SnList();
//        List<String> list5 = new ArrayList<>();
//        list5.add("CSSN010046");
//        list5.add("CSSN010047");
//        list5.add("CSSN010048");
//        list5.add("CSSN010049");
//        list5.add("CSSN010050");
//        snList4.setSn(list5);
//        orderLine5.setSnList(snList4);

        List<EntryorderCreateRequest.OrderLine> orderLines = new ArrayList<>();
        orderLines.add(orderLine1);
        orderLines.add(orderLine2);
//        orderLines.add(orderLine3);
//        orderLines.add(orderLine4);
//        orderLines.add(orderLine5);
        createRequest.setOrderLines(orderLines);
        long time1 = System.currentTimeMillis();
        EntryorderCreateResponse response = client.execute(createRequest);
        long time2 = System.currentTimeMillis();
        log.info("响应:{} ERP订单编码:{} wms仓储编码:{} 耗时:{}",
            response.getFlag(),
            response.getMessage(),
            entryOrder.getEntryOrderCode(),
            response.getEntryOrderId(),
            time2 - time1);
    }

    public static void main(String[] args)

        throws ApiException
    {
//        create();
        for (int i = 0; i < 1; i++)
        {
            create();
        }
    }

}
